﻿/*

  The contents of this file are subject to the Mozilla Public License Version
  1.1 (the "License"); you may not use this file except in compliance with
  the License. You may obtain a copy of the License at 
  
           http://www.mozilla.org/MPL/ 
  
  Software distributed under the License is distributed on an "AS IS" basis,
  WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  for the specific language governing rights and limitations under the License. 
  
  The Original Code is PEGAS Framework.
  
  The Initial Developer of the Original Code is
  ALCARAZ Marc (aka eKameleon)  <ekameleon@gmail.com>.
  Portions created by the Initial Developer are Copyright (C) 2004-2009
  the Initial Developer. All Rights Reserved.
  
  Contributor(s) :
  
*/
package examples 
{
    import pegas.geom.Matrix2;
    import pegas.geom.Vector2;
    
    import system.eden;
    
    import flash.display.Sprite;
    
    /**
     * Example of the Matrix2 class.
     */
    public class ExampleMatrix2 extends Sprite 
    {
        public function ExampleMatrix2()
        {
            var m:Matrix2 ;
            
            ////////// test constructor
            
            m = new Matrix2() ;
            trace( m ) ;
            
            // use four arguments to fill the Matrix2 object
            
            m = new Matrix2( 1, 2, 3, 4 ) ;
            trace( m ) ;
            
            // use two Vector2 arguments to fill the 2 columns of the Matrix2 object
            
            m = new Matrix2( new Vector2(1,3) , new Vector2(2,4) ) ;
            trace( m ) ;
            
            // use the angle argument
            
            m = new Matrix2( 0 ) ;
            trace( m ) ;
            
            m = new Matrix2( 12 ) ;
            trace( m ) ;
            
            // use a Matrix2 to initialize the new Matrix2
            
            m = new Matrix2( new Matrix2(1,2,3,4) ) ;
            trace( m ) ;
            
            ////////// test clone()
            
            m = new Matrix2( 1, 2, 3, 4 ) ;
            
            var clone:Matrix2 = m.clone() as Matrix2 ;
            trace( m + " clone  : " + clone ) ;
            
            ////////// test equals()
            
            m = new Matrix2( 1, 2, 3, 4 ) ;
            
            trace( m + " equals : " + m.equals(clone) ) ;
            clone.n11 = 5 ;
            trace( m + " equals : " + m.equals(clone) ) ;
            
            ////////// test getEntry()
            
            m = new Matrix2( 1, 2, 3, 4 ) ;
            
            trace( m + " getEntry(1,0) : " + m.getEntry(1,0) ) ;
            
            ////////// test identify()
            
            m = new Matrix2( 1, 2, 3, 4 ) ;
            
            m.identity() ;
            
            trace( m + " identity : " + m ) ;
            
            ////////// test getEntry()
            
            m = new Matrix2( 1, 2, 3, 4 ) ;
            
            m.setEntry( 1 , 0 , 5 ) ; // [Matrix2:[1,2],[5,4]]
            
            trace( m ) ;
            
            ////////// test toArray()
            
            m = new Matrix2( 1, 2, 3, 4 ) ;
            var a:Array = m.toArray() ;
            trace( m + " toArray() : [" + a.join(",") + "]" ) ;
            
            ////////// test toObject()
            
            m = new Matrix2( 1, 2, 3, 4 ) ;
            var o:Object = m.toObject() ;
            trace( m + " toObject() : " + eden.serialize(o) ) ;
            
            ////////// test toSource()
            
            m = new Matrix2( 1, 2, 3, 4 ) ;
            trace( m + " toSource() : " + m.toSource() ) ;
            
            ////////// test toString()
            
            m = new Matrix2( 1, 2, 3, 4 ) ;
            trace( m + " toString() : " + m.toString() ) ;
        }
    }
}
